package com.easy;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lxk on 2019/9/7.
 */
public class Solution872 {

    /**
     * 先序遍历，叶节点入列表
     *
     * @param curNode
     * @param numList
     */
    private void preOrderVisit(TreeNode curNode, List<Integer> numList) {
        if (curNode == null) {
            return;
        }
        if (curNode.left == null && curNode.right == null) {
            numList.add(curNode.val);
        }
        preOrderVisit(curNode.left, numList);
        preOrderVisit(curNode.right, numList);
    }

    /**
     * 查询判断叶节点相似
     *
     * @param root1
     * @param root2
     * @return
     */
    public boolean leafSimilar(TreeNode root1, TreeNode root2) {
        List<Integer> arr = new ArrayList<>();
        preOrderVisit(root1, arr);
        List<Integer> arr2 = new ArrayList<>();
        preOrderVisit(root2, arr2);
        if (arr.size() != arr2.size()) {
            return false;
        }
        for (int i = 0; i < arr.size(); i++) {
            if (!arr.get(i).equals(arr2.get(i))) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        TreeNode node = new TreeNode(2);

    }

}
